---
title: "Gov 2001 Replication Paper"
author: "Miro Bergam, Yanxi Fang, Dominic Skinnion"
date: "November 29, 2021"
output: pdf_document
---

# Table 1. Summary statistics 


```{r descriptive, cache=TRUE, echo=FALSE, warning=FALSE, message=FALSE, fig.pos = "H"}
library(tidyverse)
library(latex2exp)
library(kableExtra)
library(systemfonts)
library(readr)

df_replication <- read_csv("paper_replication.csv")
df_replication$CredGrowth <- df_replication$CredGrowth/10
df_replication_summary <- df_replication
# including only the 45 countries included in the model estimation
df_replication_summary <- filter(df_replication, countryname %in% c("ARGENTINA"
                                    , "AUSTRIA"
                                    , "BAHRAIN"
                                    , "BANGLADESH"
                                    , "BELGIUM"
                                    , "BRAZIL"
                                    , "CANADA"
                                    , "CHILE"
                                    , "COLOMBIA"
                                    , "COSTA RICA"
                                    , "CYPRUS"
                                    , "DENMARK"
                                    , "DOMINICAN REPUBLIC"
                                    , "FRANCE"
                                    , "GERMANY"
                                    , "GREECE"
                                    , "HONG KONG"
                                    , "INDIA"
                                    , "INDONESIA"
                                    , "IRELAND"
                                    , "ISRAEL"
                                    , "ITALY"
                                    , "JAPAN"
                                    , "KENYA"
                                    , "MALAYSIA"
                                    , "NETHERLANDS"
                                    , "NIGERIA"
                                    , "NORWAY"
                                    , "PAKISTAN"
                                    , "PARAGUAY"
                                    , "PANAMA"
                                    , "PERU"
                                    , "PHILIPPINES"
                                    , "PORTUGAL"
                                    , "SAUDI ARABIA"
                                    , "SENEGAL"
                                    , "SOUTH AFRICA"
                                    , "SWEDEN"
                                    , "SWITZERLAND"
                                    , "THAILAND"
                                    , "TUNISIA"
                                    , "TURKEY"
                                    , "UNITED KINGDOM"
                                    , "USA"
                                    , "VENEZUELA"
                                    )
       )

df_tab1 <- select(df_replication_summary, GDPgrowth_lag, Infl , realintrate, depr, tot, 
                  CredGrowth, moralhak, LegOrGer, LegOrFre, LegOrSca, LegOrEng,
                  Africa, Other, LatinAmerica, G10, conav, Ha, pcrdbgdp, foreigno,
                  govowner, activrest, entrybr, crindex, ospower, pmindex)


mean <- sapply(df_tab1, mean, na.rm=TRUE) #; mean
stdev <- sapply(df_tab1, sd, na.rm=TRUE) #; stdev
min <- sapply(df_tab1, min, na.rm=TRUE)  #; min
max <- sapply(df_tab1, max, na.rm=TRUE)  #; max
col1  <- rbind("GDP growth (lag)"
              , "Inflation"
              , "Real interest rate"
              , "Depreciation"
              , "Terms of trade"
              , "Credit growth"
              , "Moral hazard index"
              , "German legal origin"
              , "French legal origin"
              , "Scandinavian legal origin"
              , "British legal origin"
              , "Africa dummy"
              , "Other dummy"
              , "Latin America dummy"
              , "G10 dummy"
              , "Concentration"
              , "H-statistic"
              , "Private credit/GDP"
              , "Foreign ownership"
              , "Government ownership"
              , "Activity restrictions"
              , "Entry restrictions"
              , "Capital regulatory index"
              , "Official supervisory power"
              , "Private monitoring index"
              ) #; (col1)

col2  <- rbind("3.4505"
              , "15.0287"
              , "1.1214"
              , "2.1880"
              , "4.0984"
              , "11.2683"
              , "1.3058"
              , "0.0886"
              , "0.3965"
              , "0.0831"
              , "0.3910"
              , "0.1267"
              , "0.4482"
              , "0.2057"
              , "0.2193"
              , "0.6734"
              , "0.3224"
              , "0.4485"
              , "0.1499"
              , "0.4697"
              , "9.7345"
              , "7.0573"
              , "6.2054"
              , "10.6991"
              , "8.1037"
              ) #; (col2)


df_tab1sum <- tibble(col1, col2, mean, stdev, min, max)

# recreate table 1
opts <- options(knitr.kable.NA = "")
x <- knitr::kable(df_tab1sum, digits = 2
                  , caption = "Summary Statistics"
                  , escape = FALSE
                  , align= c("l", "c", "c","c", "c", "c")
                  , col.names = c('Variable ', ' Mean SCW2009 ', 'Mean', 'Std dev', 'Min', "Max")
                  , format="latex", linesep = '',  booktabs = TRUE
                  ) %>%
  kable_styling(latex_options = "striped") 
add_footnote(x, c("Source: Table 1, SCW2009, p.718; Author's estimates using \n Reed (2018) Dataverse dataset provided by SCW2009 authors"), notation = "symbol")



```




# Table 2. Crises episodes


```{r crises, echo=FALSE, cache=TRUE, as.is=TRUE, fig.pos="H", out.extra = "", message=FALSE, warning=FALSE}

library(readr)
library(latex2exp)
library(kableExtra)
library(systemfonts)
dat1 <- read_csv("crises.csv", col_names = TRUE)
opts <- options(knitr.kable.NA = "")

crises <- knitr::kable(dat1, caption = "Crises Episodes", escape = FALSE, 
                  align= c("l", "c"),
                  format="latex", booktabs = TRUE) %>%
  kable_styling(latex_options = "striped") 
add_footnote(crises, c("Source: Table 2, SCW2009, p.719"), notation = "symbol")

```



# Replication 

```{r cache=TRUE, message=FALSE, warning=FALSE, echo=FALSE}

library(readr)

df_replication <- read_csv("paper_replication.csv")

mod.logit <- glm(crisis  ~ GDPgrowth_lag + Infl + realintrate + 
                       depr +tot + creditgrowth + moralhak + LegOrGer +
                       LegOrFre + LegOrSca + Africa + Other + LatinAmerica
                       ,
                  family = binomial(link = 'logit'), data =  df_replication)  
# pseudo r-squared
mod.logit_R2<- 1-(mod.logit$deviance/mod.logit$null.deviance)
mod.logit_R2 <- round(mod.logit_R2, digits=3)


mod.hstat <- glm(crisis  ~ GDPgrowth_lag + Infl + realintrate + 
                       depr +tot + creditgrowth + moralhak + LegOrGer +
                       LegOrFre + LegOrSca + Africa + Other + LatinAmerica +
                       Ha,
                  family = binomial(link = 'logit'), data =  df_replication)  
# pseudo r-squared
mod.hstat_R2 <- 1-(mod.hstat$deviance/mod.hstat$null.deviance)
mod.hstat_R2 <-round(mod.hstat_R2, digits=3)


mod.hstat.c <- glm(crisis  ~ GDPgrowth_lag + Infl + realintrate + 
                       depr +tot + creditgrowth + moralhak + LegOrGer +
                       LegOrFre + LegOrSca + Africa + Other + LatinAmerica +
                       Ha + conav,
                  family = binomial(link = 'logit'), data =  df_replication)  
# pseudo r-squared
mod.hstat.c_R2 <- 1-(mod.hstat.c$deviance/mod.hstat.c$null.deviance)
mod.hstat.c_R2 <- round(mod.hstat.c_R2, digits=3)


mod.hstat.lc <- glm(crisis  ~ GDPgrowth_lag + Infl + realintrate + 
                       depr +tot + creditgrowth + moralhak + LegOrGer +
                       LegOrFre + LegOrSca + Africa + Other + LatinAmerica +
                       Ha*conav,
                  family = binomial(link = 'logit'), data =  df_replication)  
# pseudo r-squared
mod.hstat.lc_R2 <- 1-(mod.hstat.lc$deviance/mod.hstat.lc$null.deviance)
mod.hstat.lc_R2 <- round(mod.hstat.lc_R2, digits=3)


library(stargazer)

 stargazer(mod.logit, mod.hstat, mod.hstat.c, mod.hstat.lc,
          header = F, type = "latex", digits = 3, style = "apsr",
          title = "Logit Models (Replication)",
          column.labels = c("(5)", "(6)", "(7)", "(8)"),
          covariate.labels = c("GDP growth (lag)",
                               "Inflation", 
                               "Real interest rate",
                               "Depreciation", 
                               "Terms of trade",
                               "Credit growth", 
                               "Moral hazard index",
                               "German legal origin", 
                               "French legal origin", 
                               "Scandinavian legal origin",
                               "Africa dummy variable",
                               "Other dummy variable",
                               "H-statistic",
                               "Concentration",
                               "H-statistic*Concentration"),
          omit = c("Constant"),
          add.lines = list(
            c("Observations", "734", "707", "707", "707"),
                           c("Pseudo $R^2$", mod.logit_R2, mod.hstat_R2,
                             mod.hstat.c_R2, mod.hstat.lc_R2)))

```


## Table 3

```{r replicationlogit, echo=FALSE,  as.is=TRUE, fig.pos="H", out.extra = "", message=FALSE, warning=FALSE}

library(readr)
library(latex2exp)
library(kableExtra)
library(systemfonts)
repdat <- read_csv("tab_replication_logit.csv", col_names = TRUE)
opts <- options(knitr.kable.NA = "")

replogit <- knitr::kable(repdat, caption = "Logit Models Replication Results. Competition and concentration lowers probability of banking crisis.", escape = FALSE, 
                  align= c("l", "c", "c", "c", "c", "c", "c", "c", "c"),
                  format="latex", booktabs = TRUE) %>%
  kable_styling(latex_options = "striped")  %>%
  kable_styling(latex_options = "scale_down") %>%
  add_header_above(c("Dependent Variable:" = 1, "Baseline" = 2, "With H-statistic" = 2, "With H-stat and Concentration" = 2, "With H-stat*Concentration" = 2)) 
add_footnote(replogit, c("Source: Own estimates; Table 3, SCW2009"))


```



# Extension 

## Table 4


```{r cache=TRUE, message=FALSE, warning=FALSE, echo=FALSE}

library(readr)

df_replication <- read_csv("replication_addl.csv")
# names(df_replication)

mod.eme.logit <- glm(crisis  ~ GDPgrowth_lag + Infl + realintrate + 
                       depr +tot + creditgrowth + moralhak + LegOrGer +
                       LegOrFre + LegOrSca + Africa + Other + LatinAmerica + eme
                       ,
                  family = binomial(link = 'logit'), data =  df_replication)  

# GIM test: not misspecified
mod.eme.hstat <- glm(crisis  ~ GDPgrowth_lag + Infl + realintrate + 
                       depr +tot + creditgrowth + moralhak + LegOrGer +
                       LegOrFre + LegOrSca + Africa + Other + LatinAmerica 
                     + eme + Ha,
                  family = binomial(link = 'logit'), data =  df_replication)  


# GIM test: not misspecified
mod.eme.hstat.c <- glm(crisis  ~ GDPgrowth_lag + Infl + realintrate + 
                       depr +tot + creditgrowth + moralhak + LegOrGer +
                       LegOrFre + LegOrSca + Africa + Other + LatinAmerica 
                       + eme + Ha + conav,
                  family = binomial(link = 'logit'), data =  df_replication)  


# GIM test: >1.5, run full test
mod.eme.hstat.lc <- glm(crisis  ~ GDPgrowth_lag + Infl + realintrate + 
                       depr +tot + creditgrowth + moralhak + LegOrGer +
                       LegOrFre + LegOrSca + Africa + Other + LatinAmerica 
                       + ASEAN + Ha + conav
                       ,
                  family = binomial(link = 'logit'), data =  df_replication)  


library(stargazer)

stargazer(mod.eme.logit, mod.eme.hstat, mod.eme.hstat.c, mod.eme.hstat.lc, 
   title="Logit Models with Dummy Variable for EMEs and ASEANs", align=TRUE)


```


## Table 5. Summary statistics (ASEAN-4, 1980-2020)

```{r descriptiveasean, cache=TRUE, echo=FALSE, warning=FALSE, message=FALSE, fig.pos = "H"}
library(tidyverse)
library(latex2exp)
library(kableExtra)
library(systemfonts)
library(readr)

df_aseandesc <- read_csv("ASEANEMEs.csv")
# names(df_asean)

df_aseandesc$reservesgr <- (df_aseandesc$dlforeignreserves)*100
df_tabsumasean <- select(df_aseandesc, RGDPgrowth, Infl , realintrate, depr_USD, totgr, 
                  privcredittogdp, moralhaz_BDR2020, 
                  LegOrFre, LegOrEng, 
                  foreignreservestoARA, reservestoExtDebt, reservesgr,
                  GDPdeflator, 
                  concentration, 
                  Hstat, Lerner, Boone,
                  foreigno, govowner, activrest, entrybr, crindex, ospower, pmindex)

mean <- sapply(df_tabsumasean, mean, na.rm=TRUE) #; mean
stdev <- sapply(df_tabsumasean, sd, na.rm=TRUE) #; stdev
min <- sapply(df_tabsumasean, min, na.rm=TRUE)  #; min
max <- sapply(df_tabsumasean, max, na.rm=TRUE)  #; max
col1asean  <- rbind("GDP growth rate"
              , "Inflation"
              , "Real interest rate"
              , "Depreciation (growth rate local/USD)"
              , "Terms of trade"
              , "Lending to private sector by banks/GDP"
              , "Moral hazard index"
              , "French legal origin"
              , "British legal origin"
              , "Foreign reserves-to-IMF adequacy metric"
              , "Foreign reserves-to-external debt"
              , "Foreign reserves growth"
              , "GDP deflator index"
              , "Concentration"
              , "H-statistic"
              , "Lerner Index"
              , "Boone Indicator"
              , "Foreign ownership"
              , "Government ownership"
              , "Activity restrictions"
              , "Entry restrictions"
              , "Capital regulatory index"
              , "Official supervisory power"
              , "Private monitoring index"
              ) #; (col1asean)


df_tabsumnew <- tibble(mean, stdev, min, max) # ; df_tabsumnew
df_tabsumnew <- mutate(df_tabsumnew, col1asean)
df_tabsumnew <- df_tabsumnew %>%
  select(col1asean, everything())
# df_tab1sum

# recreate table 1
opts <- options(knitr.kable.NA = "")
xasean <- knitr::kable(df_tabsumnew, digits = 2
                  , caption = "Summary Statistics (ASEAN-4, 1980-2020)"
                  , escape = FALSE
                  , align= c("l", "c", "c","c", "c")
                  , col.names = c('Variable ', 'Mean', 'Std dev', 'Min', "Max")
                  , format="latex", linesep = '',  booktabs = TRUE
                  ) %>%
  kable_styling(latex_options = "striped")  
 add_footnote(xasean, c("Sources: Reed (2018), Bandaranayake (2019), IMF WEO Database (October 2021),\n IMF International Financial Statistics, World Bank Indicators"))

```



## Table 6. Logit Models with Different Competition Measures

```{r cache=TRUE, message=FALSE, warning=FALSE, echo=FALSE}

library(readr)
library(RobustSE)

df_asean <- read_csv("ASEANEMEs.csv")
# names(df_asean)

# significant: LernerIndex (-)
# "Max ratio of robust to classic standard errors is 0.887"
# Rule of thumb suggests your model is NOT misspecified
mod.asean.lerner01 <- glm(Crisis  ~ Lerner 
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.lerner01)
# mod.asean.lerner01.rse <- GIM(mod.asean.lerner01, full=F)



mod.asean.lerner02 <- glm(Crisis  ~ concentration 
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.lerner02)
# mod.asean.lerner02.rse <- GIM(mod.asean.lerner02, full=F)



# significant: LernerIndex (-), LernerIndex:concentration (+)
# Rule of thumb suggests your model is NOT misspecified
# Max ratio of robust to classic standard errors is 1.211
mod.asean.lerner03 <- glm(Crisis  ~ Lerner*concentration
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.lerner03)
# mod.asean.lerner03.rse <- GIM(mod.asean.lerner03, full=F)



# significant: LernerIndex (-), LernerIndex:concentration, RGDPgrowth
# GIM test: Rule of thumb suggests your model is NOT misspecified
# Max ratio of robust to classic standard errors is 1.136
mod.asean.lerner04 <- glm(Crisis  ~ Lerner*concentration + RGDPgrowth 
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.lerner04)
# mod.asean.lerner04.rse <- GIM(mod.asean.lerner04, full=F)


# significant: LernerIndex (-), RGDPgrowth, depr_USD

mod.asean.lerner05 <- glm(Crisis  ~ Lerner*concentration + RGDPgrowth + depr_USD
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.lerner05)
# mod.asean.lerner05.rse <- GIM(mod.asean.lerner05, full=F)


# significant: LernerIndex (-), LernerIndex:concentration (+)
# GIM test: not misspecified
mod.asean.lerner06 <- glm(Crisis  ~ Lerner*concentration + RGDPgrowth + privcredittogdp
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.lerner06)
# mod.asean.lerner06.rse <- GIM(mod.asean.lerner06, full=F)


# significant: LernerIndex (-), RGDPgrowth, dlforeignreserves
# GIM test: not misspecified
mod.asean.lerner07 <- glm(Crisis  ~ Lerner*concentration + RGDPgrowth + dlforeignreserves
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.lerner07)
# mod.asean.lerner07.rse <- GIM(mod.asean.lerner07, full=F)


# significant: LernerIndex (-), LernerIndex:concentration (+), RGDPgr, dlforeignreserves
mod.asean.lerner08 <- glm(Crisis  ~ Lerner*concentration + RGDPgrowth + dlforeignreserves + log(GDPdeflator)
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.lerner08)
# mod.asean.lerner08.rse <- GIM(mod.asean.lerner08, full=F)


# significant: LernerIndex (-), LernerIndex:concentration (+), RGDPgr, dlforeignreserves
# removed dlforeignreserves  to satisfy GIM test
# GIM test : not misspecified
# Max ratio of robust to classic standard errors is 1.062
mod.asean.lerner09 <- glm(Crisis  ~ Lerner*concentration + RGDPgrowth 
#                          + dlforeignreserves 
                          +  privcredittogdp 
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.lerner09)
# mod.asean.lerner09.rse <- GIM(mod.asean.lerner09, full=F)




# significant: LernerIndex, real GDP growth, foreign reserves growth, LernerIndex:concentration 
# adding moral hazard index turns the interaction term insig
mod.asean.lerner10 <- glm(Crisis  ~ Lerner*concentration + RGDPgrowth 
#                          + dlforeignreserves  
                          + privcredittogdp 
                          + foreigno
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.lerner10)
# mod.asean.lerner10.rse <- GIM(mod.asean.lerner10, full=F)




# positive sign of govowner is opposite SCW2009 finding 
# [1] "Max ratio of robust to classic standard errors is 1.462"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.lerner11 <- glm(Crisis  ~ Lerner*concentration + RGDPgrowth 
#                          + dlforeignreserves  
                          + privcredittogdp 
                       + govowner
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.lerner11)
# mod.asean.lerner11.rse <- GIM(mod.asean.lerner11, full=F)




# significant: LernerIndex (-), concentration, LernerIndex:concentration (+), RGDPgr
# "Max ratio of robust to classic standard errors is 1.407"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.lerner12 <- glm(Crisis  ~ Lerner*concentration + RGDPgrowth 
#                           + dlforeignreserves  
                          + privcredittogdp 
                       + activrest
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.lerner12)
# mod.asean.lerner12.rse <- GIM(mod.asean.lerner12, full=F)




# significant: LernerIndex (-), concentration, LernerIndex:concentration (+), RGDPgr, dlforeignreserves, entrybr
# [1] "Max ratio of robust to classic standard errors is 1.102"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.lerner13 <- glm(Crisis  ~ Lerner*concentration + RGDPgrowth 
#                          + dlforeignreserves  
                          + privcredittogdp 
                       + entrybr
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.lerner13)
# mod.asean.lerner13.rse <- GIM(mod.asean.lerner13, full=F)




# significant: LernerIndex (-), concentration, LernerIndex:concentration (+), RGDPgr
# [1] "Max ratio of robust to classic standard errors is 1.243"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.lerner14 <- glm(Crisis  ~ Lerner*concentration + RGDPgrowth 
#                          + dlforeignreserves  
                          + privcredittogdp 
                       + crindex
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.lerner14)
# mod.asean.lerner14.rse <- GIM(mod.asean.lerner14, full=F)




# significant: LernerIndex (-), concentration, LernerIndex:concentration (+), RGDPgr, dlforeignreserves
# [1] "Max ratio of robust to classic standard errors is 1.352"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.lerner15 <- glm(Crisis  ~ Lerner*concentration + RGDPgrowth 
#                           + dlforeignreserves  
                          + privcredittogdp 
                       + ospower
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.lerner15)
# mod.asean.lerner15.rse <- GIM(mod.asean.lerner15, full=F)




# significant: LernerIndex (-), concentration, LernerIndex:concentration (+), RGDPgr, dlforeignreserves
# [1] "Max ratio of robust to classic standard errors is 1.268"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.lerner16 <- glm(Crisis  ~ Lerner*concentration + RGDPgrowth 
#                          + dlforeignreserves  
                          + privcredittogdp 
                       + pmindex
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.lerner16)
# mod.asean.lerner16.rse <- GIM(mod.asean.lerner16, full=F)





# Different measures of competition, different results

## Hstat
mod.asean.hstat01 <- glm(Crisis  ~ Hstat
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.hstat01)
# mod.asean.hstat01.rse <- GIM(mod.asean.hstat01, full=F)




mod.asean.hstat02 <- glm(Crisis  ~ concentration
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.hstat02)
# mod.asean.hstat02.rse <- GIM(mod.asean.hstat02, full=F)




# [1] "Max ratio of robust to classic standard errors is 0.719"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.hstat03 <- glm(Crisis  ~ Hstat*concentration
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.hstat03)
# mod.asean.hstat03.rse <- GIM(mod.asean.hstat01, full=F)





# significant: real GDP growth 
# [1] "Max ratio of robust to classic standard errors is 1.334"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.hstat04 <- glm(Crisis  ~ Hstat*concentration + RGDPgrowth 
#                         + dlforeignreserves  
                         + privcredittogdp 
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.hstat04)
# mod.asean.hstat04.rse <- GIM(mod.asean.hstat04, full=F)





# significant: real GDP growth
# [1] "Max ratio of robust to classic standard errors is 1.35"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.hstat05 <- glm(Crisis  ~ Hstat*concentration + RGDPgrowth 
#                         + dlforeignreserves  
                         + privcredittogdp 
                       + foreigno
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.hstat05)
# mod.asean.hstat05.rse <- GIM(mod.asean.hstat05, full=F)





# significant: real GDP growth 
# [1] "Max ratio of robust to classic standard errors is 1.496"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.hstat06 <- glm(Crisis  ~ Hstat*concentration + RGDPgrowth 
#                         + dlforeignreserves  
                         + privcredittogdp 
                       + govowner
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.hstat06)
# mod.asean.hstat06.rse <- GIM(mod.asean.hstat06, full=F)





# significant: real GDP growth 
# [1] "Max ratio of robust to classic standard errors is 1.344"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.hstat07 <- glm(Crisis  ~ Hstat*concentration + RGDPgrowth 
#                         + dlforeignreserves  
                         + privcredittogdp 
                       + activrest
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.hstat07)
# mod.asean.hstat07.rse <- GIM(mod.asean.hstat07, full=F)






# significant: real GDP growth 
# [1] "Max ratio of robust to classic standard errors is 1.633"
# [1] "Rule of thumb suggests your model is misspecified, it is suggested that you run the full GIM test"
mod.asean.hstat08 <- glm(Crisis  ~ Hstat*concentration + RGDPgrowth 
#                         + dlforeignreserves  
                         + privcredittogdp 
                       + entrybr
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.hstat08)
# mod.asean.hstat08.rse <- GIM(mod.asean.hstat08, full=F)






# significant: real GDP growth 
# [1] "Max ratio of robust to classic standard errors is 1.528"
# [1] "Rule of thumb suggests your model is misspecified, it is suggested that you run the full GIM test"
mod.asean.hstat09 <- glm(Crisis  ~ Hstat*concentration + RGDPgrowth 
#                         + dlforeignreserves  
                         + privcredittogdp 
                       + crindex
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.hstat09)
# mod.asean.hstat09.rse <- GIM(mod.asean.hstat09, full=F)





# significant: real GDP growth, private credit 
# [1] "Max ratio of robust to classic standard errors is 1.684"
# [1] "Rule of thumb suggests your model is misspecified, it is suggested that you run the full GIM test"
mod.asean.hstat10 <- glm(Crisis  ~ Hstat*concentration + RGDPgrowth 
#                         + dlforeignreserves  
                         + privcredittogdp 
                       + ospower
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.hstat10)
# mod.asean.hstat10.rse <- GIM(mod.asean.hstat10, full=F)





# significant: real GDP growth
# [1] "Max ratio of robust to classic standard errors is 1.274"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.hstat11 <- glm(Crisis  ~ Hstat*concentration + RGDPgrowth 
#                         + dlforeignreserves  
                         + privcredittogdp 
                       + pmindex
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.hstat11)
# mod.asean.hstat11.rse <- GIM(mod.asean.hstat11, full=F)





## Boone Indicator

# 1] "Max ratio of robust to classic standard errors is 1.17"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.boone01 <- glm(Crisis  ~ Boone
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.boone01)
# mod.asean.boone01.rse <- GIM(mod.asean.boone01, full=F)





# [1] "Max ratio of robust to classic standard errors is 0.889"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.boone02 <- glm(Crisis  ~ concentration
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.boone02)
# mod.asean.boone02.rse <- GIM(mod.asean.boone02, full=F)




# [1] "Max ratio of robust to classic standard errors is 1.231"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.boone03 <- glm(Crisis  ~ Boone*concentration
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.boone03)
# mod.asean.boone03.rse <- GIM(mod.asean.boone03, full=F)





# significant: foreign reserves growth 
# [1] "Max ratio of robust to classic standard errors is 1.193"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.boone04 <- glm(Crisis  ~ Boone*concentration + RGDPgrowth 
#                         + dlforeignreserves  
                         + privcredittogdp 
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.boone04)
# mod.asean.boone04.rse <- GIM(mod.asean.boone04, full=F)





# significant: BooneIndicator*concentration
# [1] "Max ratio of robust to classic standard errors is 1.345"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.boone05 <- glm(Crisis  ~ Boone*concentration + RGDPgrowth 
#                         + dlforeignreserves  
                         + privcredittogdp 
                       + foreigno
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.boone05)
# mod.asean.boone05.rse <- GIM(mod.asean.boone05, full=F)





# significant: Boone Indicator, real GDP growth, private credit, govowner, Boone:concentration 
# [1] "Max ratio of robust to classic standard errors is 1.287"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.boone06 <- glm(Crisis  ~ Boone*concentration + RGDPgrowth 
#                         + dlforeignreserves  
                         + privcredittogdp 
                       + govowner
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.boone06)
# mod.asean.boone06.rse <- GIM(mod.asean.boone06, full=F)





# significant: real GDP growth, Boone:concentration 
# [1] "Max ratio of robust to classic standard errors is 1.382"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.boone07 <- glm(Crisis  ~ Boone*concentration + RGDPgrowth 
#                         + dlforeignreserves  
                         + privcredittogdp 
                       + activrest
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.boone07)
# mod.asean.boone07.rse <- GIM(mod.asean.boone07, full=F)





# significant: Boone, real GDP growth,  Boone:concentration
# [1] "Max ratio of robust to classic standard errors is 1.316"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.boone08 <- glm(Crisis  ~ Boone*concentration + RGDPgrowth 
#                         + dlforeignreserves  
                         + privcredittogdp 
                       + entrybr
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.boone08)
# mod.asean.boone08.rse <- GIM(mod.asean.boone08, full=F)






# significant: real GDP growth, Boone:concentration 
# [1] "Max ratio of robust to classic standard errors is 1.41"
# [1] "Rule of thumb suggests your model is NOT misspecified"
mod.asean.boone09 <- glm(Crisis  ~ Boone*concentration + RGDPgrowth 
#                         + dlforeignreserves  
                         + privcredittogdp 
                       + crindex
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.boone09)
# mod.asean.boone09.rse <- GIM(mod.asean.boone09, full=F)






# significant: RGDP growth, private credit
# [1] "Max ratio of robust to classic standard errors is 2.115"
# [1] "Rule of thumb suggests your model is misspecified, it is suggested that you run the full GIM test"
mod.asean.boone10 <- glm(Crisis  ~ Boone*concentration + RGDPgrowth 
#                         + dlforeignreserves 
                         + privcredittogdp 
                       + ospower
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.boone10)
# mod.asean.boone10.rse <- GIM(mod.asean.boone10, full=F)






# significant:  RGDP growth, private credit
# [1] "Max ratio of robust to classic standard errors is 1.389"
# "Rule of thumb suggests your model is NOT misspecified"
mod.asean.boone11 <- glm(Crisis  ~ Boone*concentration + RGDPgrowth 
#                         + dlforeignreserves  
                         + privcredittogdp 
                       + pmindex
                       ,
                  family = binomial(link = 'logit'), data =  df_asean)  
# summary(mod.asean.boone11)
# mod.asean.boone11.rse <- GIM(mod.asean.boone11, full=F)





# library(stargazer)

# stargazer(mod.asean.lerner03, mod.asean.hstat03, mod.asean.boone03, 
#   title="Logit Models for ASEAN-4: Different competition measures", align=TRUE)
# this gives the correct data and stats but will not compile into a nice table
# so I copied the latex table and manually modified to make it compile

```


```{r aseanmods, echo=FALSE,  as.is=TRUE, fig.pos="H", out.extra = "", message=FALSE, warning=FALSE}

mod.asean.lerner09.sum <- summary(mod.asean.lerner09, vcov = vcovHC)
mod.asean.hstat04.sum <- summary(mod.asean.hstat04, vcov = vcovHC)
mod.asean.boone04.sum <- summary(mod.asean.boone04, vcov = vcovHC)

# pseudo R-squared
mod.asean.lerner09_R2<- 1-(mod.asean.lerner09.sum$deviance/mod.asean.lerner09.sum$null.deviance)
# round(mod.asean.lerner09_R2, digits = 2)
mod.asean.hstat04_R2<- 1-(mod.asean.hstat04.sum$deviance/mod.asean.hstat04.sum$null.deviance)
# round(mod.asean.hstat04_R2, digits = 2)
mod.asean.boone04_R2<- 1-(mod.asean.boone04.sum$deviance/mod.asean.boone04.sum$null.deviance)
# round(mod.asean.boone04_R2, digits = 2)

# extract estimates and p-values
h.est04 <- mod.asean.hstat04.sum[["coefficients"]][ , "Estimate"]
h.pval04 <- mod.asean.hstat04.sum[["coefficients"]][ , "Pr(>|z|)"]
l.est09 <- mod.asean.lerner09.sum[["coefficients"]][ , "Estimate"]
l.pval09 <- mod.asean.lerner09.sum[["coefficients"]][ , "Pr(>|z|)"]
b.est04 <- mod.asean.boone04.sum[["coefficients"]][ , "Estimate"]
b.pval04 <- mod.asean.boone04.sum[["coefficients"]][ , "Pr(>|z|)"]


mod.asean_s <- cbind(h.est04, h.pval04, l.est09, l.pval09, b.est04, b.pval04)
rownames(mod.asean_s) <- c("Intercept", "Competition measure", "Concentration measure", "Real GDP growth",  "Private credit-to-GDP",  "Competition:Concentration")

opts <- options(knitr.kable.NA = "")
mods.asean <- knitr::kable(mod.asean_s, 
                              align= c("c", "c", "c", "c", "c", "c"), 
                              digits = 2,  
                              col.names = c("Coefficient", "p-value", "Coefficient", "p-value", "Coefficient", "p-value"),   
                              caption = "Logit Models with Different Competition Measures", 
                              format = "latex", booktabs = TRUE) %>%
  kable_styling(latex_options = "striped")  %>%
  kable_styling(latex_options = "scale_down") %>%
  add_header_above(c("Dependent Variable:\n Banking Crisis" = 1, "H-statistic \n(pseudo R-squared = 0.12)" = 2, "Lerner Index \n(pseudo R-squared = 0.24)" = 2, "Boone Indicator \n(pseudo R-squared = 0.13)" = 2)) 
add_footnote(mods.asean, c("Source: Author's estimates"))

```




## Taable 7. Models with Foreign Ownership Restriction

```{r foreigno, echo=FALSE,  as.is=TRUE, fig.pos="H", out.extra = "", message=FALSE, warning=FALSE}

mod.asean.lerner10.sum <- summary(mod.asean.lerner10, vcov = vcovHC)
mod.asean.hstat05.sum <- summary(mod.asean.hstat05, vcov = vcovHC)
mod.asean.boone05.sum <- summary(mod.asean.boone05, vcov = vcovHC)

# extract estimates and p-values
h.est05 <- mod.asean.hstat05.sum[["coefficients"]][ , "Estimate"]
h.pval05 <- mod.asean.hstat05.sum[["coefficients"]][ , "Pr(>|z|)"]
l.est10 <- mod.asean.lerner10.sum[["coefficients"]][ , "Estimate"]
l.pval10 <- mod.asean.lerner10.sum[["coefficients"]][ , "Pr(>|z|)"]
b.est05 <- mod.asean.boone05.sum[["coefficients"]][ , "Estimate"]
b.pval05 <- mod.asean.boone05.sum[["coefficients"]][ , "Pr(>|z|)"]

# est
# pval
# mod.asean.lerner10_s <- cbind(l.est10, l.pval10)
# knitr::kable(mod.asean.lerner10_s, align= c("c", "c"), digits = 2,  col.names = c("Estimated coefficient", "p-value"),  caption = "Coefficients: Models with Foreign Ownership Restriction", format = "pipe", padding = 2)


mod.asean.foreigno_s <- cbind(h.est05, h.pval05, l.est10, l.pval10, b.est05, b.pval05)
rownames(mod.asean.foreigno_s) <- c("Intercept", "Competition measure", "Concentration measure", "Real GDP growth",  "Private credit-to-GDP", "Foreign ownership restriction", "Competition:Concentration")

# mods.foreigno <- knitr::kable(mod.asean.foreigno_s, align= c("c", "c", "c", "c", "c", "c"), digits = 4,  col.names = c("Estimated coefficient", "p-value", "Estimated coefficient", "p-value", "Estimated coefficient", "p-value"),   caption = "Models with Foreign Ownership Restriction", format = "pipe", padding = 2)
# mods.foreigno

opts <- options(knitr.kable.NA = "")
mods.foreigno <- knitr::kable(mod.asean.foreigno_s, 
                              align= c("c", "c", "c", "c", "c", "c"), 
                              digits = 2,  
                              col.names = c("Estimated \ncoefficient", "p-value", "Estimated \ncoefficient", "p-value", "Estimated \n coefficient", "p-value"),   
                              caption = "Models with Foreign Ownership Restriction", 
                              format = "latex", booktabs = TRUE) %>%
  kable_styling(latex_options = "striped")  %>%
  kable_styling(latex_options = "scale_down") %>%
  add_header_above(c("Dependent Variable:\n Banking Crisis" = 1, "H-statistic" = 2, "Lerner Index" = 2, "Boone Indicator" = 2)) 
add_footnote(mods.foreigno, c("Source: Author's estimates"))

```




## Table 8. Models with activity restrictions 

```{r activrest, echo=FALSE,  as.is=TRUE, fig.pos="H", out.extra = "", message=FALSE, warning=FALSE, cache=TRUE}

mod.asean.lerner12.sum <- summary(mod.asean.lerner12, vcov = vcovHC)
mod.asean.hstat07.sum <- summary(mod.asean.hstat07, vcov = vcovHC)
mod.asean.boone07.sum <- summary(mod.asean.boone07, vcov = vcovHC)

# extract estimates and p-values
h.est07 <- mod.asean.hstat07.sum[["coefficients"]][ , "Estimate"]
h.pval07 <- mod.asean.hstat07.sum[["coefficients"]][ , "Pr(>|z|)"]
l.est12 <- mod.asean.lerner12.sum[["coefficients"]][ , "Estimate"]
l.pval12 <- mod.asean.lerner12.sum[["coefficients"]][ , "Pr(>|z|)"]
b.est07 <- mod.asean.boone07.sum[["coefficients"]][ , "Estimate"]
b.pval07 <- mod.asean.boone07.sum[["coefficients"]][ , "Pr(>|z|)"]



mod.asean.activrest_s <- cbind(h.est07, h.pval07, l.est12, l.pval12, b.est07, b.pval07)
rownames(mod.asean.activrest_s) <- c("Intercept", "Competition measure", "Concentration measure", "Real GDP growth",  "Private credit-to-GDP", "Activity restriction", "Competition:Concentration")



opts <- options(knitr.kable.NA = "")
mods.activrest <- knitr::kable(mod.asean.activrest_s, 
                              align= c("c", "c", "c", "c", "c", "c"), 
                              digits = 2,  
                              col.names = c("Estimated \ncoefficient", "p-value", "Estimated \ncoefficient", "p-value", "Estimated \n coefficient", "p-value"),   
                              caption = "Models with Activity Restriction", 
                              format = "latex", booktabs = TRUE) %>%
  kable_styling(latex_options = "striped")  %>%
  kable_styling(latex_options = "scale_down") %>%
  add_header_above(c("Dependent Variable:\n Banking Crisis" = 1, "H-statistic" = 2, "Lerner Index" = 2, "Boone Indicator" = 2)) 
add_footnote(mods.activrest, c("Source: Author's estimates"))

```





## Table 9. Models with entry restrictions 

```{r entrybr, echo=FALSE,  as.is=TRUE, fig.pos="H", out.extra = "", message=FALSE, warning=FALSE, cache=TRUE}

mod.asean.lerner13.sum <- summary(mod.asean.lerner13, vcov = vcovHC)
mod.asean.hstat08.sum <- summary(mod.asean.hstat08, vcov = vcovHC)
mod.asean.boone08.sum <- summary(mod.asean.boone08, vcov = vcovHC)

# extract estimates and p-values
h.est08 <- mod.asean.hstat08.sum[["coefficients"]][ , "Estimate"]
h.pval08 <- mod.asean.hstat08.sum[["coefficients"]][ , "Pr(>|z|)"]
l.est13 <- mod.asean.lerner13.sum[["coefficients"]][ , "Estimate"]
l.pval13 <- mod.asean.lerner13.sum[["coefficients"]][ , "Pr(>|z|)"]
b.est08 <- mod.asean.boone08.sum[["coefficients"]][ , "Estimate"]
b.pval08 <- mod.asean.boone08.sum[["coefficients"]][ , "Pr(>|z|)"]



mod.asean.entrybr_s <- cbind(h.est08, h.pval08, l.est13, l.pval13, b.est08, b.pval08)
rownames(mod.asean.entrybr_s) <- c("Intercept", "Competition measure", "Concentration measure", "Real GDP growth",  "Private credit-to-GDP", "Entry restrictions", "Competition:Concentration")



opts <- options(knitr.kable.NA = "")
mods.entrybr <- knitr::kable(mod.asean.entrybr_s, 
                              align= c("c", "c", "c", "c", "c", "c"), 
                              digits = 2,  
                              col.names = c("Estimated \ncoefficient", "p-value", "Estimated \ncoefficient", "p-value", "Estimated \n coefficient", "p-value"),   
                              caption = "Models with Entry Restrictions", 
                              format = "latex", booktabs = TRUE) %>%
  kable_styling(latex_options = "striped")  %>%
  kable_styling(latex_options = "scale_down") %>%
  add_header_above(c("Dependent Variable:\n Banking Crisis" = 1, "H-statistic" = 2, "Lerner Index" = 2, "Boone Indicator" = 2)) 
add_footnote(mods.entrybr, c("Source: Author's estimates"))

```




## Table 10. Models with capital regulation

```{r crindex, echo=FALSE,  as.is=TRUE, fig.pos="H", out.extra = "", message=FALSE, warning=FALSE, cache=TRUE}

mod.asean.lerner14.sum <- summary(mod.asean.lerner14, vcov = vcovHC)
mod.asean.hstat09.sum <- summary(mod.asean.hstat09, vcov = vcovHC)
mod.asean.boone09.sum <- summary(mod.asean.boone09, vcov = vcovHC)

# extract estimates and p-values
h.est09 <- mod.asean.hstat09.sum[["coefficients"]][ , "Estimate"]
h.pval09 <- mod.asean.hstat09.sum[["coefficients"]][ , "Pr(>|z|)"]
l.est14 <- mod.asean.lerner14.sum[["coefficients"]][ , "Estimate"]
l.pval14 <- mod.asean.lerner14.sum[["coefficients"]][ , "Pr(>|z|)"]
b.est09 <- mod.asean.boone09.sum[["coefficients"]][ , "Estimate"]
b.pval09 <- mod.asean.boone09.sum[["coefficients"]][ , "Pr(>|z|)"]



mod.asean.crindex_s <- cbind(h.est09, h.pval09, l.est14, l.pval14, b.est09, b.pval09)
rownames(mod.asean.crindex_s) <- c("Intercept", "Competition measure", "Concentration measure", "Real GDP growth",  "Private credit-to-GDP", "Capital regulatory index", "Competition:Concentration")



opts <- options(knitr.kable.NA = "")
mods.crindex <- knitr::kable(mod.asean.crindex_s, 
                              align= c("c", "c", "c", "c", "c", "c"), 
                              digits = 2,  
                              col.names = c("Estimated \ncoefficient", "p-value", "Estimated \ncoefficient", "p-value", "Estimated \n coefficient", "p-value"),   
                              caption = "Models with Capital Regulatory Index", 
                              format = "latex", booktabs = TRUE) %>%
  kable_styling(latex_options = "striped")  %>%
  kable_styling(latex_options = "scale_down") %>%
  add_header_above(c("Dependent Variable:\n Banking Crisis" = 1, "H-statistic" = 2, "Lerner Index" = 2, "Boone Indicator" = 2)) 
add_footnote(mods.crindex, c("Source: Author's estimates"))

```




## Table 11 Models with index on official supervisory powers

```{r ospower, echo=FALSE,  as.is=TRUE, fig.pos="H", out.extra = "", message=FALSE, warning=FALSE, cache=TRUE}

mod.asean.lerner15.sum <- summary(mod.asean.lerner15, vcov = vcovHC)
mod.asean.hstat10.sum <- summary(mod.asean.hstat10, vcov = vcovHC)
mod.asean.boone10.sum <- summary(mod.asean.boone10, vcov = vcovHC)

# extract estimates and p-values
h.est10 <- mod.asean.hstat10.sum[["coefficients"]][ , "Estimate"]
h.pval10 <- mod.asean.hstat10.sum[["coefficients"]][ , "Pr(>|z|)"]
l.est15 <- mod.asean.lerner15.sum[["coefficients"]][ , "Estimate"]
l.pval15 <- mod.asean.lerner15.sum[["coefficients"]][ , "Pr(>|z|)"]
b.est10 <- mod.asean.boone10.sum[["coefficients"]][ , "Estimate"]
b.pval10 <- mod.asean.boone10.sum[["coefficients"]][ , "Pr(>|z|)"]



mod.asean.ospower_s <- cbind(h.est10, h.pval10, l.est15, l.pval15, b.est10, b.pval10)
rownames(mod.asean.ospower_s) <- c("Intercept", "Competition measure", "Concentration measure", "Real GDP growth",  "Private credit-to-GDP", "Supervisory powers index", "Competition:Concentration")



opts <- options(knitr.kable.NA = "")
mods.ospower <- knitr::kable(mod.asean.ospower_s, 
                              align= c("c", "c", "c", "c", "c", "c"), 
                              digits = 2,  
                              col.names = c("Estimated \ncoefficient", "p-value", "Estimated \ncoefficient", "p-value", "Estimated \n coefficient", "p-value"),   
                              caption = "Models with Index on Supervisory Powers", 
                              format = "latex", booktabs = TRUE) %>%
  kable_styling(latex_options = "striped")  %>%
  kable_styling(latex_options = "scale_down") %>%
  add_header_above(c("Dependent Variable:\n Banking Crisis" = 1, "H-statistic" = 2, "Lerner Index" = 2, "Boone Indicator" = 2)) 
add_footnote(mods.ospower, c("Source: Author's estimates"))

```




## Table 12. Models with index on private monitoring index

```{r pmindex, echo=FALSE,  as.is=TRUE, fig.pos="H", out.extra = "", message=FALSE, warning=FALSE, cache=TRUE}

mod.asean.lerner16.sum <- summary(mod.asean.lerner16, vcov = vcovHC)
mod.asean.hstat11.sum <- summary(mod.asean.hstat11, vcov = vcovHC)
mod.asean.boone11.sum <- summary(mod.asean.boone11, vcov = vcovHC)

# extract estimates and p-values
h.est11 <- mod.asean.hstat11.sum[["coefficients"]][ , "Estimate"]
h.pval11 <- mod.asean.hstat11.sum[["coefficients"]][ , "Pr(>|z|)"]
l.est16 <- mod.asean.lerner16.sum[["coefficients"]][ , "Estimate"]
l.pval16 <- mod.asean.lerner16.sum[["coefficients"]][ , "Pr(>|z|)"]
b.est11 <- mod.asean.boone11.sum[["coefficients"]][ , "Estimate"]
b.pval11 <- mod.asean.boone11.sum[["coefficients"]][ , "Pr(>|z|)"]



mod.asean.pmindex_s <- cbind(h.est11, h.pval11, l.est16, l.pval16, b.est11, b.pval11)
rownames(mod.asean.pmindex_s) <- c("Intercept", "Competition measure", "Concentration measure", "Real GDP growth",  "Private credit-to-GDP", "Index on private monitoring of banks", "Competition:Concentration")



opts <- options(knitr.kable.NA = "")
mods.pmindex <- knitr::kable(mod.asean.pmindex_s, 
                              align= c("c", "c", "c", "c", "c", "c"), 
                              digits = 2,  
                              col.names = c("Estimated \n coefficient", "p-value", "Estimated \n coefficient", "p-value", "Estimated \n coefficient", "p-value"),   
                              caption = "Models with Index on Private Monitoring of Banks", 
                              format = "latex", booktabs = TRUE) %>%
  kable_styling(latex_options = "striped")  %>%
  kable_styling(latex_options = "scale_down") %>%
  add_header_above(c("Dependent Variable:\n Banking Crisis" = 1, "H-statistic" = 2, "Lerner Index" = 2, "Boone Indicator" = 2)) 
add_footnote(mods.pmindex, c("Source: Author's estimates"))

```



## Figures

### Figure 1. 

```{r predprobs, fig.cap="Changes in Predicted Probabilities of Banking Crisis (1980-2005). Increases in competition and concentration lower the predicted probability of a banking crisis. Non-EMEs and Non-ASEANs have lower predicted probability of a banking crisis." , message=FALSE, warning=FALSE, cache=TRUE, echo=FALSE}

library(margins)

par(mfrow = c(2, 2))

cplot(mod.hstat.c, "Ha", what = "prediction",
      xlab = "H-statistic", ylim = c(0, 0.2),
      main = "Predicted probability of Banking Crisis", cex.main=0.7, cex.lab=1, cex.axis=1)

cplot(mod.hstat.c, "conav", what = "prediction",
      xlab = "Concentration Measure", ylim = c(0, 0.2),
      main = "Predicted probability of Banking \nCrisis", cex.main=0.7, cex.lab=1, cex.axis=1)

cplot(mod.eme.hstat.c, "eme", what = "prediction",
      xlab = "DV:EMEs", ylim = c(0, 0.2),
      main = "Predicted probability of Banking Crisis", cex.main=0.7, cex.lab=1, cex.axis=1)

cplot(mod.eme.hstat.lc, "ASEAN", what = "prediction",
      xlab = "DV:ASEAN", ylim = c(0, 0.2),
      main = "Predicted probability of Banking Crisis", cex.main=0.7, cex.lab=1, cex.axis=1)



```


### Figure 2. 

```{r predprobsnew, fig.cap= "Predicted Probabilities of Banking Crisis and the Different Competition Measures (ASEAN-4). Increase in competition could increase on the predicted probability of crisis, contrary to results for the dataset with 45 heterogeneous economies (1980-2005). The effect of concentration on predicted probability of banking crisis is also not as clear cut.", cache=TRUE, echo=FALSE, fig.height=6, eval=T}

library(margins)

par(mfrow= c(3,2))
cplot(mod.asean.lerner09, "Lerner", what = "prediction",
      xlab = "Lerner Index", ylim = c(0, 1), 
      main = "Predicted probability of Banking Crisis", cex.main=0.85, cex.lab=0.9, cex.axis=0.9)

cplot(mod.asean.lerner09, "concentration", what = "prediction",
      xlab = "Concentration Measure \n(Model using Lerner Index)", ylim = c(0, 0.25), 
      main = "Predicted probability of Banking Crisis", cex.main=0.85, cex.lab=0.9, cex.axis=0.9)

cplot(mod.asean.hstat04, "Hstat", what = "prediction",
      xlab = "H-statistic", ylim = c(0, 0.25), 
      main = "Predicted probability of Banking Crisis", cex.main=0.85, cex.lab=0.9, cex.axis=0.9)

cplot(mod.asean.hstat04, "concentration", what = "prediction",
      xlab = "Concentration Measure\n(Model using H-statistic)", ylim = c(0, 0.25),
      main = "Predicted probability of Banking Crisis", cex.main=0.85, cex.lab=0.9, cex.axis=0.9)


cplot(mod.asean.boone04, "Boone", what = "prediction",
      xlab = "Boone Indicator", ylim = c(0, 0.25), 
      main = "Predicted probability of Banking Crisis", cex.main=0.85, cex.lab=0.9, cex.axis=0.9)

cplot(mod.asean.boone04, "concentration", what = "prediction",
      xlab = "Concentration Measure\n(Model using Boone Indicator)", ylim = c(0, 0.25), 
      main = "Predicted probability of Banking Crisis", cex.main=0.85, cex.lab=0.9, cex.axis=0.9)


```



### Figure 3. 

```{r macropru,fig.cap= "Logit models with different competition measures and with macroprudential policies and regulation (at 90 CI). The opposite impacts of competition and concentration on financial stability becomes apparent when controls for regulatory environment and macroprudential policy are introduced.", echo=FALSE,  as.is=TRUE, fig.pos="H", out.extra = "", message=FALSE, warning=FALSE, fig.height=5.85, fig.width=10}
library(ggplot2)
library(tidyverse)
library(broom)

# Multiple plot function
# Source: http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/
# ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects)
# - cols:   Number of columns in layout
# - layout: A matrix specifying the layout. If present, 'cols' is ignored.
#
# If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE),
# then plot 1 will go in the upper left, 2 will go in the upper right, and
# 3 will go all the way across the bottom.
#
multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {
  library(grid)

  # Make a list from the ... arguments and plotlist
  plots <- c(list(...), plotlist)

  numPlots = length(plots)

  # If layout is NULL, then use 'cols' to determine layout
  if (is.null(layout)) {
    # Make the panel
    # ncol: Number of columns of plots
    # nrow: Number of rows needed, calculated from # of cols
    layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
                    ncol = cols, nrow = ceiling(numPlots/cols))
  }

 if (numPlots==1) {
    print(plots[[1]])

  } else {
    # Set up the page
    grid.newpage()
    pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))

    # Make each plot, in the correct location
    for (i in 1:numPlots) {
      # Get the i,j matrix positions of the regions that contain this subplot
      matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))

      print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
                                      layout.pos.col = matchidx$col))
    }
  }
}



# foreigno
plot.foreigno <- tidy(mod.asean.lerner10) %>%
  mutate(mdl="Lerner") %>%
  bind_rows(tidy(mod.asean.hstat05) %>% mutate(mdl="H-stat")) %>%
  bind_rows(tidy(mod.asean.boone05) %>% mutate(mdl="Boone")) %>%
ggplot(aes(x = term,
           y = estimate, 
           ymin= estimate - 1.645*std.error, # 10% 1.645; 5% 1.96
           ymax= estimate + 1.645*std.error,
           color=mdl)) +
  coord_flip() +
  geom_hline(yintercept = 0, lty=3) +
  geom_pointrange(position = position_dodge(width=.8), size=.1) +
  theme_bw() +
  theme(legend.position = "top", 
        axis.text = element_text(size=7)
#        , legend.title=element_text(size=7)
        , legend.title = element_blank()
        , axis.text.x = element_text(angle = 0)
        , legend.text=element_text(size=8)
        , plot.title = element_text(size = 10, face = "bold")
        , axis.title=element_text(size=8, face = "plain")
        , legend.box = "vertical"
        ) 

# activrest
plot.activrest <- tidy(mod.asean.lerner12) %>%
  mutate(mdl="Lerner Index") %>%
  bind_rows(tidy(mod.asean.hstat07) %>% mutate(mdl="H-statistic")) %>%
  bind_rows(tidy(mod.asean.boone07) %>% mutate(mdl="Boone Indicator")) %>%
ggplot(aes(x = term,
           y = estimate, 
           ymin= estimate - 1.645*std.error, # 10% 1.645; 5% 1.96
           ymax= estimate + 1.645*std.error,
           color=mdl)) +
  coord_flip() +
  geom_hline(yintercept = 0, lty=3) +
  geom_pointrange(position = position_dodge(width=.8), size=.1) +
  theme_bw() +
  theme(legend.position = "none", 
         axis.text = element_text(size=7)
        , legend.title=element_text(size=7)
        , axis.text.x = element_text(angle = 0)
        , legend.text=element_text(size=7)
        , plot.title = element_text(size = 10, face = "bold")
        , axis.title=element_text(size=8, face = "plain")
        )



# entrybr
plot.entrybr <- tidy(mod.asean.lerner13) %>%
  mutate(mdl="Lerner Index") %>%
  bind_rows(tidy(mod.asean.hstat08) %>% mutate(mdl="H-statistic")) %>%
  bind_rows(tidy(mod.asean.boone08) %>% mutate(mdl="Boone Indicator")) %>%
ggplot(aes(x = term,
           y = estimate, 
           ymin= estimate - 1.645*std.error, # 10% 1.645; 5% 1.96
           ymax= estimate + 1.645*std.error,
           color=mdl)) +
  coord_flip() +
  geom_hline(yintercept = 0, lty=3) +
  geom_pointrange(position = position_dodge(width=.8), size=.1) +
  theme_bw() +
  theme(legend.position = "none", 
         axis.text = element_text(size=7)
        , legend.title=element_text(size=7)
        , axis.text.x = element_text(angle = 0)
        , legend.text=element_text(size=7)
        , plot.title = element_text(size = 10, face = "bold")
        , axis.title=element_text(size=8, face = "plain")
        )


#crindex
plot.crindex <- tidy(mod.asean.lerner14) %>%
  mutate(mdl="Lerner Index") %>%
  bind_rows(tidy(mod.asean.hstat09) %>% mutate(mdl="H-statistic")) %>%
  bind_rows(tidy(mod.asean.boone09) %>% mutate(mdl="Boone Indicator")) %>%
ggplot(aes(x = term,
           y = estimate, 
           ymin= estimate - 1.645*std.error, # 10% 1.645; 5% 1.96
           ymax= estimate + 1.645*std.error,
           color=mdl)) +
  coord_flip() +
  geom_hline(yintercept = 0, lty=3) +
  geom_pointrange(position = position_dodge(width=.8), size=.1) +
  theme_bw() +
  theme(legend.position = "none", 
         axis.text = element_text(size=7)
        , legend.title=element_text(size=7)
        , axis.text.x = element_text(angle = 0)
        , legend.text=element_text(size=7)
        , plot.title = element_text(size = 10, face = "bold")
        , axis.title=element_text(size=8, face = "plain")
        )

# ospower
plot.ospower <- tidy(mod.asean.lerner15) %>%
  mutate(mdl="Lerner Index") %>%
  bind_rows(tidy(mod.asean.hstat10) %>% mutate(mdl="H-statistic")) %>%
  bind_rows(tidy(mod.asean.boone10) %>% mutate(mdl="Boone Indicator")) %>%
ggplot(aes(x = term,
           y = estimate, 
           ymin= estimate - 1.645*std.error, # 10% 1.645; 5% 1.96
           ymax= estimate + 1.645*std.error,
           color=mdl)) +
  coord_flip() +
  geom_hline(yintercept = 0, lty=3) +
  geom_pointrange(position = position_dodge(width=.8), size=.1) +
  theme_bw() +
  theme(legend.position = "none", 
         axis.text = element_text(size=7)
        , legend.title=element_text(size=7)
        , axis.text.x = element_text(angle = 0)
        , legend.text=element_text(size=7)
        , plot.title = element_text(size = 10, face = "bold")
        , axis.title=element_text(size=8, face = "plain")
        )


# pmindex
plot.pmindex <- tidy(mod.asean.lerner16) %>%
  mutate(mdl="Lerner Index") %>%
  bind_rows(tidy(mod.asean.hstat11) %>% mutate(mdl="H-statistic")) %>%
  bind_rows(tidy(mod.asean.boone11) %>% mutate(mdl="Boone Indicator")) %>%
ggplot(aes(x = term,
           y = estimate, 
           ymin= estimate - 1.645*std.error, # 10% 1.645; 5% 1.96
           ymax= estimate + 1.645*std.error,
           color=mdl)) +
  coord_flip() +
  geom_hline(yintercept = 0, lty=3) +
  geom_pointrange(position = position_dodge(width=.8), size=.1) +
  theme_bw() +
  theme(legend.position = "none",
         axis.text = element_text(size=7)
        , legend.title=element_text(size=7)
        , axis.text.x = element_text(angle = 0)
        , legend.text=element_text(size=7)
        , plot.title = element_text(size = 10, face = "bold")
        , axis.title=element_text(size=8, face = "plain")
        )

multiplot(plot.foreigno
                  , plot.activrest
                  , plot.entrybr
                  , plot.crindex
                  , plot.ospower
                  , plot.pmindex
                  , cols=3)

```














